package com.plian.system.controller.fr.bank;


import com.plian.system.dto.fr.bank.BankRecordDTO;
import com.plian.system.model.CommonCode;
import com.plian.system.model.R;
import com.plian.system.service.fr.bank.IBankKeyService;
import com.plian.system.service.fr.bank.IBankRecordService;
import com.plian.system.vo.report.ReportReturnVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * 推送记录
 */
@RestController
@RequestMapping("api/record")
@AllArgsConstructor
public class BankRecordController {

    private IBankRecordService bankRecordService;

    private IBankKeyService bankKeyService;


//    /**
//     * 保存日志
//     *
//     * @param bankRecord
//     * @return
//     */
//    @PostMapping(value = "/submit")
//    @PassToken
//    public R saveRecode(@RequestBody BankRecord bankRecord) {
//        BankKey bankKey = bankKeyService.getOne(new QueryWrapper<BankKey>().eq("app_id", bankRecord.getAppId()));
//        if (bankKey != null) {
//            bankRecord.setTopGroupId(bankKey.getTopGroupId());
//            bankRecord.setTopGroupName(bankKey.getTopGroupName());
//        }
//        bankRecord.setRecordDate(new Date());
//        return bankRecordService.save(bankRecord)
//                ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//    }
//
//    @PostMapping("/list")
//    @PassToken
//    public ListResult<BankRecordVO> list(@RequestBody Query query) {
//        List<SearchEntity> entityList = query.getSearch();
//        if (query.getAscs() == null && query.getDescs() == null) {
//            query.setDescs("create_time");
//        }
//        QueryWrapper<BankRecord> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new BankRecord()), entityList
//        );
//        if (!Optional.ofNullable(query.getFlag()).isPresent() || query.getFlag() != 1) {
//            queryWrapper.and(wrapper -> wrapper.or().eq("top_group_id", TokenUtil.getTokenOrgId()));
//        }
//        IPage<BankRecord> pages = bankRecordService.page(Condition.getPage(query), queryWrapper);
//        List<BankRecordVO> projectInfoVOS = BankRecordWrapper.build().pageVO(pages).getRecords();
//        ListResult<BankRecordVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(projectInfoVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//    }

    /**
     * 银行数据采集点监控
     *
     * @param bankRecordDTO
     * @return
     */
    @PostMapping("/statistics")
    public R<ReportReturnVO> statistics(@RequestBody BankRecordDTO bankRecordDTO) throws ParseException {
        R<ReportReturnVO> result = new R<>(CommonCode.SUCCESS);
        result.setPageData(bankRecordService.statistics(bankRecordDTO));
        return result;
    }

}
